<?php
namespace common\models\shop;

use common\models\Common;
use yii\db\ActiveRecord;

class GoodsCategoryRelation extends Common
{
    public static function tableName()
    {
        return '{{%goods_category_relation}}';
    }

    public function getCategoryId() {
        return $this->hasMany(static::className(), ['category_id' => 'goods_id']);
    }

    // 通过分类ID获取商品ID
    public static function searchByCategory($category_id = '') {
        $where['category_id'] = $category_id;

        $list = static::getByWhere($where, ['goods_id']);

        return array_column($list, "goods_id");
    }
}